﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MedicalAdviser.Portable.DataTypes.WsTypes;
using Action = MedicalAdviser.Portable.DataTypes.WsTypes.Action;
using log = MedicalAdviser.Loggin;

namespace MedicalAdviser.Controllers.WsValidation
{
    public class ResquestIntegretyController
    {

        public static void VerifyActionParameter(AppInteration interation )
        {
            if (interation == null)
            {
                log.Loggin.LOGGER.WriteEvent(
                   "Interaction parameter is null or empy "
                   ,log.LogginType.RequestParmeterError);
                throw new Exception("Request parameter is not present on request. ");
            }
            else
            {
                if (interation.Action == Action.Notting)
                {
                    log.Loggin.LOGGER.WriteEvent(
                    "Action is wrong"
                        , log.LogginType.RequestParmeterError);
                    throw new Exception("Error on action code.");
                }
                else
                {
                    if (interation.ClientAuth == null || interation.ClientAuth.AccessToken == null ||
                        interation.ClientAuth.AccessToken.Length == 0)
                    {
                        log.Loggin.LOGGER.WriteEvent(
                            "Acesson token is empty or null, this parameter the operation canot continue whitout this parameter"
                            , log.LogginType.UserCredentialMiss);
                        throw new Exception("This operation need user credentials.");
                    }
                }

            }
        }

    }
}
